package site.isscloud.framework.config.properties;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * MQTT配置属性
 */
@Component
@ConfigurationProperties(prefix = "mqtt")
public class MqttProperties {

    /**
     * 是否启用MQTT
     */
    private boolean enabled = false;

    /**
     * Broker服务器地址
     */
    private String brokerUrl = "tcp://localhost:1883";

    /**
     * 客户端ID
     */
    private String clientId = "isscloud-default";

    /**
     * 用户名
     */
    private String username;

    /**
     * 密码
     */
    private String password;

    /**
     * 主题配置
     */
    private Map<String, String> topics = new HashMap<>();

    /**
     * QoS配置
     */
    private Map<String, Integer> qos = new HashMap<>();

    /**
     * 连接超时时间（秒）
     */
    private int connectionTimeout = 30;

    /**
     * 心跳间隔（秒）
     */
    private int keepAliveInterval = 60;

    /**
     * 是否自动重连
     */
    private boolean automaticReconnect = true;

    /**
     * 是否清洁会话
     */
    private boolean cleanSession = true;

    /**
     * 最大飞行消息数
     */
    private int maxInflight = 100;

    // Getter和Setter方法
    public boolean isEnabled() {
        return enabled;
    }

    public void setEnabled(boolean enabled) {
        this.enabled = enabled;
    }

    public String getBrokerUrl() {
        return brokerUrl;
    }

    public void setBrokerUrl(String brokerUrl) {
        this.brokerUrl = brokerUrl;
    }

    public String getClientId() {
        return clientId;
    }

    public void setClientId(String clientId) {
        this.clientId = clientId;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Map<String, String> getTopics() {
        return topics;
    }

    public void setTopics(Map<String, String> topics) {
        this.topics = topics;
    }

    public Map<String, Integer> getQos() {
        return qos;
    }

    public void setQos(Map<String, Integer> qos) {
        this.qos = qos;
    }

    public int getConnectionTimeout() {
        return connectionTimeout;
    }

    public void setConnectionTimeout(int connectionTimeout) {
        this.connectionTimeout = connectionTimeout;
    }

    public int getKeepAliveInterval() {
        return keepAliveInterval;
    }

    public void setKeepAliveInterval(int keepAliveInterval) {
        this.keepAliveInterval = keepAliveInterval;
    }

    public boolean isAutomaticReconnect() {
        return automaticReconnect;
    }

    public void setAutomaticReconnect(boolean automaticReconnect) {
        this.automaticReconnect = automaticReconnect;
    }

    public boolean isCleanSession() {
        return cleanSession;
    }

    public void setCleanSession(boolean cleanSession) {
        this.cleanSession = cleanSession;
    }

    public int getMaxInflight() {
        return maxInflight;
    }

    public void setMaxInflight(int maxInflight) {
        this.maxInflight = maxInflight;
    }

    /**
     * 获取实时数据主题
     */
    public String getRealtimeTopic() {
        return topics.getOrDefault("realtime", "isscloud/elevator/realtime");
    }

    /**
     * 获取告警数据主题
     */
    public String getAlarmTopic() {
        return topics.getOrDefault("alarm", "isscloud/elevator/alarm");
    }

    /**
     * 获取实时数据QoS
     */
    public int getRealtimeQos() {
        return qos.getOrDefault("realtime", 0);
    }

    /**
     * 获取告警数据QoS
     */
    public int getAlarmQos() {
        return qos.getOrDefault("alarm", 1);
    }
}